import request from '@/utils/request'
import type { PageResult } from '@/types/process'
import type { InstanceVo, ProcessInstanceQuery, BpmnModelViewVo } from '@/types/flow'

// 获取流程实例分页列表
export function getProcessInstancePage(params: ProcessInstanceQuery) {
  return request<PageResult<InstanceVo>>({
    url: '/instance/list',
    method: 'post',
    data: params,
  })
}

// 获取流程实例的BPMN模型视图
export function getBpmnModelView(id: string) {
  return request<BpmnModelViewVo>({
    url: '/instance/getBpmnModelView',
    method: 'post',
    params: { id },
  })
}

/**
 * 发起流程实例
 * @param data 流程参数
 */
export function startProcessInstance(data: any) {
  return request({
    url: '/flow/process-instance/start',
    method: 'post',
    data,
  })
}

// 终止流程实例
export function stopProcessInstance(id: string) {
  return request({
    url: '/instance/stopProcessInstance',
    method: 'post',
    params: { id },
  })
}
